package org.myxdb.core.database;

import java.util.List;

import org.myxdb.core.config.*;
import org.myxdb.core.object.Database;

public class database {
	 public boolean createdb(String name)
	 {
		 Database db=new Database();
		 
		 db.setName(name);
		 
		 DB DB= new DB(System.getProperty("user.dir")+"/conf/data.xml");
		 
		 DB.read();
		 
		 if(DB.exist(db.getName()))
		 {
		 DB.addDB(db);
		 
		 DB.write("utf-8");
		 
		 return true;
		 }
		 else return false;
	 }
	 public boolean deletedb(String name)
	 {
		 Database db = new Database();
		 
		 db.setName(name);
		 
		 DB DB = new DB(System.getProperty("user.dir")+"/conf/data.xml");
		 DB.read();
		 DB.delDB(db);
		 DB.write("utf-8");
		 
		 
		 
		 return true;
	 }
	 public boolean renamedb(String oldname,String newname)
	 {
		 Database db = new Database();
		 
		 db.setName(oldname);
		 
		 DB DB = new DB(System.getProperty("user.dir")+"/conf/data.xml");
		 DB.read();
		 DB.addDB(db);
		 DB.write("utf-8");
		 return true;
	 }
	 
	 public List listdb()
	 {
		 DB DB = new DB(System.getProperty("user.dir")+"/conf/data.xml");
		 DB.read();
		 
		 List list = DB.Available();
		 return list ;
	 }
	 public static void main(String args[])
	 {
		 List list = new database().listdb();
		 for(int i=0;i<list.size();i++)
		 {
			 System.out.println(list.get(i));
			 
		 }
	}
	 

}
